import axios from "axios";
import config from "../config/Config.js";

const dictHttp = {
    /**
     * 加载客户级别的字典信息
     * @param {} callBack 
     */
    getCustomerLevel(callBack) {
        axios.get(config.BASE_URL + "/dict/getCustomerLevel").then(res => callBack(res.data));
    },
    /**
     * 加载客户类别的字典信息
     * @param {} callBack 
     */
    getCustomerCat(callBack) {
        axios.get(config.BASE_URL + "/dict/getCustomerCat").then(res => callBack(res.data));
    },
    /**
     * 加载客户区域的字典信息
     * @param {} callBack 
     */
    getCustomerArea(callBack) {
        axios.get(config.BASE_URL + "/dict/getCustomerArea").then(res => callBack(res.data));
    },

    /**
     * 保存字典字段数据
     * @param {*} dictData 
     * @param {*} callBack 
     */
    saveDictData(dictData, callBack) {
        if (dictData != undefined) {
            axios.post(config.BASE_URL + "/dictData/save", dictData).then(res => callBack(res.data));
        }
    },
    /**
     * 根据字典编号查询这个字典的所有的字段列表
     * @param {*} dictId 
     * @param {*} callBack 
     */
    listDictDataByDictId(dictId, callBack) {
        if (dictId != undefined) {
            let url = config.BASE_URL + "/dictData/list?dictId=" + dictId;
            axios.get(url).then(res => callBack(res.data));
        }
    },

    /**
     * 添加字典信息
     * @param {*} dict 要添加的数据
     * @param {*} callBack  添加完成之后的回调函数
     */
    save(dict, callBack) {
        if (dict != undefined) {
            axios.post(config.BASE_URL + "/dict/save", dict).then(res => callBack(res.data));
        }
    },
    /**
     * 多条件分页查询
     * @param {*} dict 
     * @param {*} page 
     * @param {*} limit 
     * @param {*} callBack 
     */
    list(dict, page = 1, limit = 10, callBack) {
        let url = config.BASE_URL + "/dict/list?page=" + page + "&limit=" + limit;
        // 拼接请求参数
        if (dict != undefined) {
            if (dict.dictName != undefined) {
                url += "&dictName=" + dict.dictName;
            }
            if (dict.dictStatus != undefined) {
                url += "&dictStatus=" + dict.dictStatus;
            }
        }
        // 查询数据
        axios.get(url).then(res => callBack(res.data));
    }
}

export default dictHttp;